{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3415c4da-785a-48d0-8a8f-424f6d9d3c09",
   "metadata": {},
   "source": [
    "### 属性表中直接统计符合条件的条数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d342665f-2427-45ea-890e-6234421f2836",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>PAC</th>\n",
       "      <th>NAME</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "      <td>POLYGON ((114.33905 30.63016, 114.34839 30.621...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      PAC NAME                                           geometry\n",
       "0  420106  武昌区  POLYGON ((114.33905 30.63016, 114.34839 30.621..."
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import geopandas as gpd\n",
    "\n",
    "# 读取武昌区边界数据\n",
    "wuchang_district = gpd.read_file(r'data/武昌区.shp')\n",
    "wuchang_district"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "9d513551-5533-43e9-96c0-0ea0864be7ff",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ADDRESS</th>\n",
       "      <th>ADMINCODE</th>\n",
       "      <th>AIRPT_CODE</th>\n",
       "      <th>CHAINCODE</th>\n",
       "      <th>DATA_SRC</th>\n",
       "      <th>DISPLAY_X</th>\n",
       "      <th>DISPLAY_Y</th>\n",
       "      <th>FOOD_TYPE</th>\n",
       "      <th>IMPORTANCE</th>\n",
       "      <th>KIND</th>\n",
       "      <th>...</th>\n",
       "      <th>PRIOR_AUTH</th>\n",
       "      <th>PYNAME</th>\n",
       "      <th>SIDE</th>\n",
       "      <th>TELEPHONE</th>\n",
       "      <th>TEL_TYPE</th>\n",
       "      <th>VADMINCODE</th>\n",
       "      <th>ZIPCODE</th>\n",
       "      <th>fid_1</th>\n",
       "      <th>type</th>\n",
       "      <th>geometry</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>解放路</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.29851</td>\n",
       "      <td>30.54346</td>\n",
       "      <td>3014</td>\n",
       "      <td>2</td>\n",
       "      <td>1680</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjwxcttpz</td>\n",
       "      <td>R</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.29306 30.54589)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>古田四路和长丰大道交叉口</td>\n",
       "      <td>420104</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.21855</td>\n",
       "      <td>30.60692</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjcfct</td>\n",
       "      <td>R</td>\n",
       "      <td>027-83827943</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.21307 30.60935)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>中山大道276</td>\n",
       "      <td>420104</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.26907</td>\n",
       "      <td>30.56913</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjwsct</td>\n",
       "      <td>R</td>\n",
       "      <td>027-85379531</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.26364 30.57158)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>江汉二路181附2</td>\n",
       "      <td>420102</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.29393</td>\n",
       "      <td>30.58633</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjjqjct</td>\n",
       "      <td>R</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.28849 30.58876)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>百步亭花园路</td>\n",
       "      <td>420102</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.32181</td>\n",
       "      <td>30.64333</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjbbthylct</td>\n",
       "      <td>L</td>\n",
       "      <td>15727020034</td>\n",
       "      <td>27</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.31634 30.6457)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>徐东大街33</td>\n",
       "      <td>420111</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.34691</td>\n",
       "      <td>30.58825</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjkxmct</td>\n",
       "      <td>L</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.34141 30.59059)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>70</th>\n",
       "      <td>珞喻路726</td>\n",
       "      <td>420111</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.39692</td>\n",
       "      <td>30.5067</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjlxgcct</td>\n",
       "      <td>R</td>\n",
       "      <td>027-87456610</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430074</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.39139 30.50902)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>71</th>\n",
       "      <td>建设大道937</td>\n",
       "      <td>420102</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.28539</td>\n",
       "      <td>30.60662</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjwfct</td>\n",
       "      <td>L</td>\n",
       "      <td>027-82618205</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430015</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.27996 30.60905)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>72</th>\n",
       "      <td>古田四路和长丰大道交叉口</td>\n",
       "      <td>420104</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>114.21847</td>\n",
       "      <td>30.60671</td>\n",
       "      <td>3015</td>\n",
       "      <td>2</td>\n",
       "      <td>1680</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjcfcttpz</td>\n",
       "      <td>L</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.21299 30.60914)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>73</th>\n",
       "      <td>南国西汇生活广场1楼</td>\n",
       "      <td>420104</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.22258</td>\n",
       "      <td>30.58375</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>kdjhxct</td>\n",
       "      <td>R</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.21711 30.58619)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>74 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "         ADDRESS ADMINCODE AIRPT_CODE CHAINCODE DATA_SRC  DISPLAY_X DISPLAY_Y  \\\n",
       "0            解放路    420106       None      8008        0  114.29851  30.54346   \n",
       "1   古田四路和长丰大道交叉口    420104       None      8008        0  114.21855  30.60692   \n",
       "2        中山大道276    420104       None      8008        0  114.26907  30.56913   \n",
       "3      江汉二路181附2    420102       None      8008        0  114.29393  30.58633   \n",
       "4         百步亭花园路    420102       None      8008        0  114.32181  30.64333   \n",
       "..           ...       ...        ...       ...      ...        ...       ...   \n",
       "69        徐东大街33    420111       None      8008        0  114.34691  30.58825   \n",
       "70        珞喻路726    420111       None      8008        0  114.39692   30.5067   \n",
       "71       建设大道937    420102       None      8008        0  114.28539  30.60662   \n",
       "72  古田四路和长丰大道交叉口    420104       None      None        0  114.21847  30.60671   \n",
       "73    南国西汇生活广场1楼    420104       None      8008        0  114.22258  30.58375   \n",
       "\n",
       "   FOOD_TYPE IMPORTANCE  KIND  ... PRIOR_AUTH       PYNAME SIDE     TELEPHONE  \\\n",
       "0       3014          2  1680  ...       None   kdjwxcttpz    R          None   \n",
       "1       3009          2  10C1  ...       None      kdjcfct    R  027-83827943   \n",
       "2       3009          2  10C1  ...       None      kdjwsct    R  027-85379531   \n",
       "3       3009          2  10C1  ...       None     kdjjqjct    R          None   \n",
       "4       3009          2  10C1  ...       None  kdjbbthylct    L   15727020034   \n",
       "..       ...        ...   ...  ...        ...          ...  ...           ...   \n",
       "69      3009          2  10C1  ...       None     kdjkxmct    L          None   \n",
       "70      3009          2  10C1  ...       None    kdjlxgcct    R  027-87456610   \n",
       "71      3009          2  10C1  ...       None      kdjwfct    L  027-82618205   \n",
       "72      3015          2  1680  ...       None   kdjcfcttpz    L          None   \n",
       "73      3009          2  10C1  ...       None      kdjhxct    R          None   \n",
       "\n",
       "   TEL_TYPE VADMINCODE ZIPCODE fid_1 type                    geometry  \n",
       "0      None       None    None   0.0  0.0  POINT (114.29306 30.54589)  \n",
       "1        17       None    None   0.0  0.0  POINT (114.21307 30.60935)  \n",
       "2        17       None  430000   0.0  0.0  POINT (114.26364 30.57158)  \n",
       "3      None       None    None   0.0  0.0  POINT (114.28849 30.58876)  \n",
       "4        27       None    None   0.0  0.0   POINT (114.31634 30.6457)  \n",
       "..      ...        ...     ...   ...  ...                         ...  \n",
       "69     None       None    None   0.0  0.0  POINT (114.34141 30.59059)  \n",
       "70       17       None  430074   0.0  0.0  POINT (114.39139 30.50902)  \n",
       "71       17       None  430015   0.0  0.0  POINT (114.27996 30.60905)  \n",
       "72     None       None    None   0.0  0.0  POINT (114.21299 30.60914)  \n",
       "73     None       None    None   0.0  0.0  POINT (114.21711 30.58619)  \n",
       "\n",
       "[74 rows x 27 columns]"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 读取KFC门店数据\n",
    "kfc_data = gpd.read_file(r'data/KFC.shp')\n",
    "kfc_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "0633a035-b17d-46dc-aefe-a4234b4212ab",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 检查并转换KFC门店数据的CRS使其与武昌区边界数据一致\n",
    "if kfc_data.crs!= wuchang_district.crs:\n",
    "    kfc_data = kfc_data.to_crs(wuchang_district.crs)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "877b8c0a-704c-4195-8220-acfde9bcf448",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ADDRESS</th>\n",
       "      <th>ADMINCODE</th>\n",
       "      <th>AIRPT_CODE</th>\n",
       "      <th>CHAINCODE</th>\n",
       "      <th>DATA_SRC</th>\n",
       "      <th>DISPLAY_X</th>\n",
       "      <th>DISPLAY_Y</th>\n",
       "      <th>FOOD_TYPE</th>\n",
       "      <th>IMPORTANCE</th>\n",
       "      <th>KIND</th>\n",
       "      <th>...</th>\n",
       "      <th>TELEPHONE</th>\n",
       "      <th>TEL_TYPE</th>\n",
       "      <th>VADMINCODE</th>\n",
       "      <th>ZIPCODE</th>\n",
       "      <th>fid_1</th>\n",
       "      <th>type</th>\n",
       "      <th>geometry</th>\n",
       "      <th>index_right</th>\n",
       "      <th>PAC</th>\n",
       "      <th>NAME_right</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>解放路</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.29851</td>\n",
       "      <td>30.54346</td>\n",
       "      <td>3014</td>\n",
       "      <td>2</td>\n",
       "      <td>1680</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.29306 30.54589)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>徐东大街18号销品茂1层</td>\n",
       "      <td>420111</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.34343</td>\n",
       "      <td>30.58908</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-68898145</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.33793 30.59143)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>武昌火车站交通综合体地下商业区内（西广场出站口）</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.31711</td>\n",
       "      <td>30.52956</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.31165 30.53197)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>解放路257</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.29747</td>\n",
       "      <td>30.53793</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-88060865</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.29202 30.54036)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>云鹤大厦1楼</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.30731</td>\n",
       "      <td>30.54026</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-88055638</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.30185 30.54268)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>汉街027号</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.34371</td>\n",
       "      <td>30.55554</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>15717130179</td>\n",
       "      <td>27</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.33822 30.5579)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>31</th>\n",
       "      <td>汉街027号</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>114.34379</td>\n",
       "      <td>30.55548</td>\n",
       "      <td>3015</td>\n",
       "      <td>2</td>\n",
       "      <td>1680</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.3383 30.55784)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>32</th>\n",
       "      <td>中南国际城二期旁</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.32875</td>\n",
       "      <td>30.53489</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-87258309</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.32328 30.53729)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>34</th>\n",
       "      <td>中商广场购物中心旁</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0</td>\n",
       "      <td>114.33247</td>\n",
       "      <td>30.53715</td>\n",
       "      <td>3015</td>\n",
       "      <td>2</td>\n",
       "      <td>1680</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.32699 30.53954)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>39</th>\n",
       "      <td>中北路3</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.33795</td>\n",
       "      <td>30.54817</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-87277882</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.33247 30.55055)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>44</th>\n",
       "      <td>中商广场购物中心旁</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.3325</td>\n",
       "      <td>30.5372</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-68784697</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.32702 30.53959)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>54</th>\n",
       "      <td>友谊大道2号</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.31798</td>\n",
       "      <td>30.55235</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-88873990</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.31252 30.55475)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>55</th>\n",
       "      <td>解放路407号</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.29848</td>\n",
       "      <td>30.54338</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-88848384</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.29303 30.54581)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>61</th>\n",
       "      <td>水果湖路23</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.34545</td>\n",
       "      <td>30.54727</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>027-87895650</td>\n",
       "      <td>17</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.33996 30.54963)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>62</th>\n",
       "      <td>武昌火车站西广场公交综合体2楼商铺</td>\n",
       "      <td>420106</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.31696</td>\n",
       "      <td>30.53118</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>430000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.3115 30.53359)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>69</th>\n",
       "      <td>徐东大街33</td>\n",
       "      <td>420111</td>\n",
       "      <td>None</td>\n",
       "      <td>8008</td>\n",
       "      <td>0</td>\n",
       "      <td>114.34691</td>\n",
       "      <td>30.58825</td>\n",
       "      <td>3009</td>\n",
       "      <td>2</td>\n",
       "      <td>10C1</td>\n",
       "      <td>...</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>None</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>POINT (114.34141 30.59059)</td>\n",
       "      <td>0</td>\n",
       "      <td>420106</td>\n",
       "      <td>武昌区</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>16 rows × 30 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                     ADDRESS ADMINCODE AIRPT_CODE CHAINCODE DATA_SRC  \\\n",
       "0                        解放路    420106       None      8008        0   \n",
       "8               徐东大街18号销品茂1层    420111       None      8008        0   \n",
       "10  武昌火车站交通综合体地下商业区内（西广场出站口）    420106       None      8008        0   \n",
       "26                    解放路257    420106       None      8008        0   \n",
       "28                    云鹤大厦1楼    420106       None      8008        0   \n",
       "29                    汉街027号    420106       None      8008        0   \n",
       "31                    汉街027号    420106       None      None        0   \n",
       "32                  中南国际城二期旁    420106       None      8008        0   \n",
       "34                 中商广场购物中心旁    420106       None      None        0   \n",
       "39                      中北路3    420106       None      8008        0   \n",
       "44                 中商广场购物中心旁    420106       None      8008        0   \n",
       "54                    友谊大道2号    420106       None      8008        0   \n",
       "55                   解放路407号    420106       None      8008        0   \n",
       "61                    水果湖路23    420106       None      8008        0   \n",
       "62         武昌火车站西广场公交综合体2楼商铺    420106       None      8008        0   \n",
       "69                    徐东大街33    420111       None      8008        0   \n",
       "\n",
       "    DISPLAY_X DISPLAY_Y FOOD_TYPE IMPORTANCE  KIND  ...     TELEPHONE  \\\n",
       "0   114.29851  30.54346      3014          2  1680  ...          None   \n",
       "8   114.34343  30.58908      3009          2  10C1  ...  027-68898145   \n",
       "10  114.31711  30.52956      3009          2  10C1  ...          None   \n",
       "26  114.29747  30.53793      3009          2  10C1  ...  027-88060865   \n",
       "28  114.30731  30.54026      3009          2  10C1  ...  027-88055638   \n",
       "29  114.34371  30.55554      3009          2  10C1  ...   15717130179   \n",
       "31  114.34379  30.55548      3015          2  1680  ...          None   \n",
       "32  114.32875  30.53489      3009          2  10C1  ...  027-87258309   \n",
       "34  114.33247  30.53715      3015          2  1680  ...          None   \n",
       "39  114.33795  30.54817      3009          2  10C1  ...  027-87277882   \n",
       "44   114.3325   30.5372      3009          2  10C1  ...  027-68784697   \n",
       "54  114.31798  30.55235      3009          2  10C1  ...  027-88873990   \n",
       "55  114.29848  30.54338      3009          2  10C1  ...  027-88848384   \n",
       "61  114.34545  30.54727      3009          2  10C1  ...  027-87895650   \n",
       "62  114.31696  30.53118      3009          2  10C1  ...          None   \n",
       "69  114.34691  30.58825      3009          2  10C1  ...          None   \n",
       "\n",
       "   TEL_TYPE VADMINCODE ZIPCODE fid_1 type                    geometry  \\\n",
       "0      None       None    None   0.0  0.0  POINT (114.29306 30.54589)   \n",
       "8        17       None    None   0.0  0.0  POINT (114.33793 30.59143)   \n",
       "10     None       None  430000   0.0  0.0  POINT (114.31165 30.53197)   \n",
       "26       17       None  430000   0.0  0.0  POINT (114.29202 30.54036)   \n",
       "28       17       None  430000   0.0  0.0  POINT (114.30185 30.54268)   \n",
       "29       27       None  430000   0.0  0.0   POINT (114.33822 30.5579)   \n",
       "31     None       None  430000   0.0  0.0   POINT (114.3383 30.55784)   \n",
       "32       17       None    None   0.0  0.0  POINT (114.32328 30.53729)   \n",
       "34     None       None    None   0.0  0.0  POINT (114.32699 30.53954)   \n",
       "39       17       None  430000   0.0  0.0  POINT (114.33247 30.55055)   \n",
       "44       17       None    None   0.0  0.0  POINT (114.32702 30.53959)   \n",
       "54       17       None  430000   0.0  0.0  POINT (114.31252 30.55475)   \n",
       "55       17       None    None   0.0  0.0  POINT (114.29303 30.54581)   \n",
       "61       17       None  430000   0.0  0.0  POINT (114.33996 30.54963)   \n",
       "62     None       None  430000   0.0  0.0   POINT (114.3115 30.53359)   \n",
       "69     None       None    None   0.0  0.0  POINT (114.34141 30.59059)   \n",
       "\n",
       "   index_right     PAC NAME_right  \n",
       "0            0  420106        武昌区  \n",
       "8            0  420106        武昌区  \n",
       "10           0  420106        武昌区  \n",
       "26           0  420106        武昌区  \n",
       "28           0  420106        武昌区  \n",
       "29           0  420106        武昌区  \n",
       "31           0  420106        武昌区  \n",
       "32           0  420106        武昌区  \n",
       "34           0  420106        武昌区  \n",
       "39           0  420106        武昌区  \n",
       "44           0  420106        武昌区  \n",
       "54           0  420106        武昌区  \n",
       "55           0  420106        武昌区  \n",
       "61           0  420106        武昌区  \n",
       "62           0  420106        武昌区  \n",
       "69           0  420106        武昌区  \n",
       "\n",
       "[16 rows x 30 columns]"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 基于点在面内的关系进行空间连接\n",
    "result = gpd.sjoin(kfc_data, wuchang_district, how='inner', predicate='within')\n",
    "result"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "536ad27d-74f3-49a8-8368-c4c32d3098af",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "FOOD_TYPE\n",
      "3009    13\n",
      "3014     1\n",
      "3015     2\n",
      "dtype: int64\n",
      "武昌区的KFC有 16 个\n"
     ]
    }
   ],
   "source": [
    "# 统计武昌区内的KFC门店数量\n",
    "kfc_count = result.groupby(\"FOOD_TYPE\").size()\n",
    "print(kfc_count)\n",
    "print(f\"武昌区的KFC有 {result.shape[0]} 个\")"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.13.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
